package tests;

import static org.junit.Assert.*;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;

import model.Meeting;
import model.MeetingBuilder;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
 * This class tests the Meeting class
 * 
 * @author b_aldosa
 * @since June 17 2013
 */
public class TestMeeting {

	Meeting SUT,meeting2;
	MeetingBuilder builder;
	Date date;
	Timestamp currentTime;
	/**
	 * This method is called before every test case to initialize the objects
	 */
	@Before
	public void setUp()
	{
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
		builder=new MeetingBuilder();
		SUT=builder.setAttendees("attendees")
				.setDescription("descriptrion")
				.setEnd(currentTime)
				.setStart(currentTime)
				.setLocation("location")
				.setOwner("owner")
				.setRevisionId(1)
				.setTopic("topic")
				.build();
		
		meeting2=builder.setStart(currentTime)
						.setEnd(currentTime)
						.build();
	}
	/**
	 * This method is called after each test case to nullify
	 * the objects
	 */
	@After
	public void tearDown()
	{
		date=null;
		currentTime=null;
		SUT=null;
	}

	/**
	 * This test case tests the get Id method
	 */
	@Test
	public void testGetId() {
		assertEquals(0,SUT.getId());
	}
	/**
	 * This test case tests the set Id method
	 */
	@Test
	public void testSetId() {
		SUT.setId(2);
		assertEquals(2,SUT.getId());
		
	}
	/**
	 * This test case tests the get owner method
	 */
	@Test
	public void testGetOwner() {
		assertEquals("owner",SUT.getOwner());
	}
	/**
	 * This test case tests the set owner method
	 */
	@Test
	public void testSetOwner() {
		SUT.setOwner("owner2");
		assertEquals("owner2",SUT.getOwner());
	}
	/**
	 * This test case test the get revision id method
	 */
	@Test
	public void testGetRevisionId() {
		assertEquals(1,SUT.getRevisionId());
	}
	/**
	 * This test case tests the set revision id method
	 */
	@Test
	public void testSetRevisionId() {
		SUT.setRevisionId(2);
		assertEquals(2,SUT.getRevisionId());
	}
	/**
	 * This test case tests the get topic method
	 */
	@Test
	public void testGetTopic() {
		assertEquals("topic",SUT.getTopic());
	}
	/**
	 * This test case tests the set topic method
	 */
	@Test
	public void testSetTopic() {
		SUT.setTopic("topic2");
		assertEquals("topic2",SUT.getTopic());
	}
	/**
	 * This test case tests the get location method
	 */
	@Test
	public void testGetLocation() {
		assertEquals("location",SUT.getLocation());
	}
	/**
	 * This test case tests the set location method
	 */
	@Test
	public void testSetLocation() {
		SUT.setLocation("location2");
		assertEquals("location2",SUT.getLocation());
		
	}
	/**
	 * This test case tests the get start method
	 */
	@Test
	public void testGetStart() {
		assertEquals("class java.sql.Timestamp",SUT.getStart().getClass().toString());
	}
	/**
	 * This test case tests the set start method
	 */
	@Test
	public void testSetStart() {
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
		SUT.setStart(currentTime);
		assertEquals(currentTime,SUT.getStart());
	}
	/**
	 * This test case tests the get end method
	 */
	@Test
	public void testGetEnd() {
		assertEquals("class java.sql.Timestamp",SUT.getEnd().getClass().toString());
	}
	/**
	 * This test case tests the set end method
	 */
	@Test
	public void testSetEnd() {
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
		SUT.setEnd(currentTime);
		assertEquals(currentTime,SUT.getEnd());
	}
	/**
	 * This test case tests the get attendees method
	 */
	@Test
	public void testGetAttendees() {
		assertEquals("attendees",SUT.getAttendees());
	}
	/**
	 * This test case tests the set attendees method
	 */
	@Test
	public void testSetAttendees() {
		SUT.setAttendees("attendees2");
		assertEquals("attendees2",SUT.getAttendees());
	}
	/**
	 * This test case tests the get description method
	 */
	@Test
	public void testGetDescription() {
		assertEquals("descriptrion",SUT.getDescription());
	}
	/**
	 * This test case tests the set description method
	 */
	@Test
	public void testSetDescription() {
		SUT.setDescription("description2");
		assertEquals("description2",SUT.getDescription());
	}
	/**
	 * This test case tests the get transfer object method
	 */
	@Test
	public void testGetTransferObject() {
		HashMap<String, String> result=SUT.getTransferObject();
		assertEquals(9,result.size());
	}
	/**
	 * This test case tests the has same dates method
	 */
	@Test
	public void testHasSameDates() {
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
		meeting2.setEnd(currentTime);
		meeting2.setStart(currentTime);
		long m=5*60*1000;
		Timestamp theNewTimestamp=new Timestamp (currentTime.getTime()+m);
		meeting2.setEnd(theNewTimestamp);
		meeting2.setStart(theNewTimestamp);
		assertFalse(SUT.hasSameDates(meeting2));
		SUT.setEnd(theNewTimestamp);
		SUT.setStart(theNewTimestamp);
		assertTrue(SUT.hasSameDates(meeting2));
	}	
	/**
	 * This test case tests the dates overlap method
	 */
	@Test
	public void testDatesOverLap() {
		assertFalse(SUT.datesOverLap(meeting2));
		
	}

}
